home *** CD-ROM | disk | FTP | other *** search
/ CD Ware Multimedia 1995 May / cd Ware (Juegos) Epimundo.iso / DOS / C / AVLTREE.ZIP / TESTAVL.C < prev    next >
Encoding:
C/C++ Source or Header  |  1987-03-24  |  1.2 KB  |  53 lines

  1. /* testavl.c - test AVL tree funcs */
  2.  
  3. #include <stdio.h>
  4. #include <malloc.h>
  5. #include "avltree.h"
  6.  
  7. main(argc, argv)
  8. int argc; char *argv[]; {
  9.  
  10.     char command[30], *key, *data;
  11.     avl_tree t = NULL, node;
  12.  
  13.     while (1)   {
  14.         printf("avl>");
  15.         scanf("%s", command);
  16.  
  17.             /* add command */
  18.  
  19.         if (strcmpi(command, "add") == 0)   {
  20.             key = calloc(1, 32);
  21.             data = calloc(1, 80);
  22.             scanf("%s %[^\n]", key, data);
  23.             avl_insert(key, data, &t);
  24.             }
  25.  
  26.             /* view command */
  27.  
  28.         else if (strcmpi(command, "view") == 0)
  29.             sideview(0, t);
  30.  
  31.             /* find command */
  32.  
  33.         else if (strcmpi(command, "find") == 0) {
  34.             key = calloc(1, 32);
  35.             scanf("%s", key);
  36.             node = find_in_tree(key, t);
  37.             if (node == NULL)
  38.                 printf("%s not found\n", key);
  39.             else
  40.                 printf("%s:%s\n", key, node->avl_data);
  41.             free(key);
  42.             }
  43.  
  44.             /* exit command */
  45.  
  46.         else if (strcmpi(command, "exit") == 0 || feof(stdin))
  47.             exit(0);
  48.  
  49.         else
  50.             fprintf(stderr, "Unknown command %s\n", command);
  51.         }
  52.     }
  53.